package io.louis.vmq;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServer {
    public static void main(String[] args){
        try {
            ServerSocket serverSocket = new ServerSocket(7071);
            Socket socket = new Socket();
            while (true){
                System.out.println("循环等待");
                socket = serverSocket.accept();
                InputStream in = socket.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                System.out.println("System.out.println(br.readLine());");
                String msg;
                while ((msg = br.readLine()) != null){
                    System.out.println(br.readLine());
                }

                InetAddress address = socket.getInetAddress();
                System.out.println(address.getHostAddress());

                PrintWriter printWriter = new PrintWriter(socket.getOutputStream(),true);
                printWriter.println("HTTP/1.1 200 OK");
                printWriter.println("Content-Type:text/html;charset=utf-8");
                String body = "hello,nio1";
                printWriter.println("Content-Length:" + body.getBytes().length);
                printWriter.println();
                printWriter.write("body");
                printWriter.close();
                socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
